package me.zhengjie.modules.website.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotBlank;

import lombok.Data;
import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.system.domain.User;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

/**
 * @author system
 * @since 2024-09-26 16:06:29
 */
@Entity
@Data
@Table(name = "column_table")
@ApiModel(value = "ColumnTable", description = " ")
public class ColumnTable extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @Column(name = "column_id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long columnId;

    /**
     *
     */
    @Column(name = "column_title")
    private String columnTitle;

    /**
     *
     */
    @Column(name = "column_type")
    private String columnType;

    /**
     *
     */
    @Column(name = "column_description")
    private String columnDescription;

    /**
     *
     */
    @Column(name = "status")
    private String status;

    /**
     *
     */
    @Column(name = "sort_order")
    private Integer sortOrder;

    /**
     *
     */
    @Column(name = "column_level")
    private Integer columnLevel;

    /**
     *
     */
    @Column(name = "column_url")
    private String columnUrl;

    /**
     *
     */
    @Column(name = "open_method")
    private String openMethod;


    // 数据库中的imgPath字段，保存为逗号分隔的字符串
    @JsonIgnore
    @Column(name = "img_path")
    private String imgPath;

    /**
     *
     */
    @Column(name = "parent_column_id")
    private Long parentColumnId;


    @Transient
    private List<ColumnTable> secondLevelColumns;


    // 用于和前端交互的imgPath数组
    @Transient
    private List<String> imgPathList;

   // 在加载实体时，将数据库的逗号分隔的字符串转换为List<String>
    @PostLoad
    public void postLoad() {
        if (imgPath != null && !imgPath.isEmpty()) {
            this.imgPathList = Arrays.asList(imgPath.split(","));
        } else {
            this.imgPathList = new ArrayList<>();
        }
    }

    /*
    // 在保存实体之前，将List<String>转换为逗号分隔的字符串
    @PrePersist
    @PreUpdate
    public void prePersist() {
        if (imgPathList != null && !imgPathList.isEmpty()) {
            this.imgPath = String.join(",", imgPathList);
        } else {
            this.imgPath = null;
        }
    }*/
}
